import { ModalProps } from 'antd'
import { useState } from 'react'

export const useModal = (_title: string, onCancel?: () => void) => {
    const [open, setOpen] = useState<boolean>(false)
    const [extra, setExtra] = useState<any>()
    const [title, setTitle] = useState<string>(_title)
    const props: ModalProps = {
        open: open,
        onCancel: () => {
            setOpen(false)
            onCancel && onCancel()
        },
        destroyOnClose: true,
        title: title,
        footer: null
    }
    return {
        props,
        open,
        setOpen: (open: boolean, extra?: any)=>{
            setOpen(open)
            extra && setExtra(extra)
        },
        extra,
        setTitle
    }
}

